﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edge.Common.Utils;

namespace Shop.Business.Domain.Orders.Logic
{
    public class FialedRestriction
    {
        private string description;
        private IOperation operation;


        public FialedRestriction(string description, IOperation operation)
        {
            this.description = description;
            this.operation = operation;
        }


        public string Description
        {
            get { return description; }
        }

        public IOperation Operation
        {
            get { return operation; }
        }
    }

    public class RestrictionException : OperationException
    {
        private ICollection<FialedRestriction> fails;



        public RestrictionException(IOperation operation, string message)
            : base(message)
        {
            fails = new List<FialedRestriction>();
            fails.Add(new FialedRestriction(message, operation));
        }


        public RestrictionException(IOperation operation, string message, string restrictionDescription)
            : base(message)
        {
            fails = new List<FialedRestriction>();
            fails.Add(new FialedRestriction(restrictionDescription, operation));
        }


        public RestrictionException(ICollection<FialedRestriction> fails)
            : base("")
        {
            this.fails = fails;
        }

        public string RestrictionDescription
        {
            get
            {
                if (fails.Count == 0)
                    return string.Empty;
                return CollectionsUtils.GetElement(fails, 0).Description;
            }
        }

        public IOperation Operation
        {
            get
            {
                if (fails.Count == 0)
                    return null;
                return CollectionsUtils.GetElement(fails, 0).Operation;
            }
        }

        public ICollection<FialedRestriction> Fails
        {
            get
            {
                return fails;
            }
        }

    }
}
